package backend.service.admin;

import backend.model.admin.WorkDetail;
import backend.model.admin.Workplace;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkDetailServiceImpl extends DBModelServiceImpl<WorkDetail> implements WorkDetailService {

    @Override
    public Class<WorkDetail> getEntityClass() {
        return WorkDetail.class;
    }

    @Override
    public List<WorkDetail> loadAllWorkDetails() {
        return dbModelDao.findByNamedQuery("loadAllWorkDetails");
    }

    @Override
    public List<WorkDetail> loadAllActiveWorkDetailsForWorkplace() {
        return dbModelDao.findByNamedQuery("loadAllActiveWorkDetailsForWorkplace");
    }

    @Override
    public WorkDetail loadWorkDetailByDescriptionAndWorkplace(String description, Workplace workplace) {
        List<WorkDetail> workDetailByDescriptionAndWorkplaceList = dbModelDao.findByNamedQueryAndParams("loadWorkDetailByDescriptionAndWorkplace",
                new String[]{"description", "workplace"}, new Object[]{description, workplace});
        if (workDetailByDescriptionAndWorkplaceList.size() == 1) {
            return workDetailByDescriptionAndWorkplaceList.get(0);
        }
        return null;
    }
}
